<%
layout("/layouts/platform.html"){
%>
<%DIRECTIVE DYNAMIC;%>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-default navbar-btn" href="${base}/platform/section" data-pjax><i class="ti-angle-left" id="goback"></i> 返回</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="companyAddForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/section/editDo" method="post">
                <input type="hidden" name="id" value="${obj.section.id!}"/>
                <input type="hidden" name="createAt" value="${obj.section.createAt!}"/>
                <div class="row mb10">
                    <div class="col-lg-12">
                    	<div class="form-group">
                            <label for="region_id" class="col-sm-2 control-label">选择片区</label>
							
                            <div class="col-sm-8">
                                <select id="region_id" name="region_id" class="form-control" required="required">
                                	<%for(region in obj.regions){%>
                                		 <option value="${region.id}" <% if(obj.section.region_id==region.id){ %> selected="selected" <% } %>>${region.name}</option>
                                	<%}%>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="section_name" class="col-sm-2 control-label">标题</label>

                            <div class="col-sm-8">
                                <input type="text" id="section_name" class="form-control" name="section_name"  placeholder="标题" value="${obj.section.section_name!}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="remark" class="col-sm-2 control-label">简介</label>

                            <div class="col-sm-8">
                                <input type="text" id="remark" class="form-control" name="remark"  placeholder="简介" value="${obj.section.remark!}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="section_tag" class="col-sm-2 control-label">位置</label>

                            <div class="col-sm-8">
                                <input type="text" id="section_tag" class="form-control" name="section_tag" data-parsley-required="true" placeholder="位置" value="${obj.section.section_tag!}" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="config" class="col-sm-2 control-label">配置</label>

                            <div class="col-sm-8">
                                <input type="text" id="config" class="form-control" name="config"  placeholder="配置" value="${obj.section.config!}" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="state" class="col-sm-2 control-label">状态</label>

                            <div class="col-sm-8">
                                 <input type="radio" name="state" data-parsley-required="true" value="0" <% if(obj.section.state ==0){%>checked="checked"<%}%> />启用
                                 <input type="radio" name="state" data-parsley-required="true" value="1" <% if(obj.section.state ==1){%>checked="checked"<%}%> />禁用
                            </div>
                        </div>
                        <div class="form-group has-feedback">
                            <label for="parentId" class="col-sm-2 control-label">选择资源</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <input id="parentId" type="text" class="form-control" placeholder="选择资源" disabled
                                           value="<%if(!isEmpty(obj.resourcesNames)){%>${obj.resourcesNames}<%}%>" data-parsley-required="true"/>

			                             		<span class="input-group-btn">
			                             			<button type="button" class="btn btn-primary" data-toggle="modal"
                                                            data-target="#dialogSelectParentUnit"><i class="ti-plus"></i>选择
                                                    </button>
			                             		</span>
                                </div>
                                <input type="hidden" name="resourceid" value="<%if(!isEmpty(obj.resourcesids)){%>${obj.resourcesids}<%}%>">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>

                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
                        </div>
                    </div>
                </div>
            </form>
        </section>
    </div>
</div>
<!-- 选择资源 -->
<div id="dialogSelectParentUnit" class="modal fade bs-modal-sm" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">选择资源</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div id="jsTreeParentUnit" class="demo"></div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                <button type="button" class="btn btn-primary" onclick="selectParentMenu()">确认选择</button>
            </div>
        </div>
    </div>
</div>
<a class="exit-offscreen"></a>
<script language="JavaScript">
	function initTreeView() {
	    $("#jsTreeParentUnit").jstree({
	        plugins: ["wholerow","json_data","checkbox","ui",],
	        core: {
	            data: {
	                dataType: "json",
	                url: function (node) {
	                    return node.id === "#" ? "${base}/platform/section/tree" : "${base}/platform/tree/section"
	                }
	            },
	            multiple: true
	        }
	    }).on("dblclick.jstree", function (node) {
	        selectParentMenu();
	    });
	}
	//选择菜单
	function selectParentMenu() {
	    var tree = $.jstree.reference("#jsTreeParentUnit");
	    var node = tree.get_selected(true);
	    var namevar= "";
	    var idvar= "";
	    for(var i=0;i<node.length;i++){
	    	namevar+=node[i].text+",";
	    	idvar+=node[i].id+",";
	    }
	    namevar=namevar.substring(0,namevar.length-1);
	    idvar=idvar.substring(0,idvar.length-1);
	    $("#companyAddForm #parentId").val(namevar);
	    $("#companyAddForm input[name='resourceid']").val(idvar);
	    $("#dialogSelectParentUnit").modal("hide");
	}
    $(document).ready(function () {
    	initTreeView();
        $('#companyAddForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
            },
            success: function (data, statusText, xhr, form) {
                if (data.code==0) {
                    Toast.success(data.msg);
                    setTimeout(function () {
                        $("#goback").trigger("click");
                    }, 1000);
                } else {
                    Toast.error(data.msg);
                }
            }
        });
    });
</script>
<%}%>